import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Controler {
	public ClientGui clnGui;
	public Client cln;
	
	public Controler(ClientGui clnGui ,Client cln){
		this.clnGui=clnGui;
		this.cln=cln;

		this.clnGui.addStartListener(new StartListener());
		this.clnGui.addCloseListener(new CloseListener());
	}
	
	class StartListener implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			try {
				//start watku klienta
				cln.start();
				clnGui.disableStart();
			} catch (Exception e1) {
				e1.printStackTrace();
				clnGui.showError(e1.getMessage());
			}
		}
	}
	
	class CloseListener implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			cln.endThread();
			try {
				cln.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if( !cln.isAlive() ){
				clnGui.dispose();
			}
		}
	}
}
